<?php

namespace app\services\tencentCloud\sms;

class SmsUtils
{
    /**
     * @var string
     */
    const ADD = '+';

    /**
     * @param string $code
     * @return array
     */
    public static function getRegion(string $code = 'CN'): array
    {
        $info = [
            'CN' => [
                'region' => 'China', 'name' => '中国', 'code' => 'CN', 'area_code' => 86
            ],
            'PH' => [
                'region' => 'Philippines', 'name' => '菲律宾', 'code' => 'PH', 'area_code' => 63
            ],
            'VN' => [
                'region' => 'Vietnam', 'name' => '越南', 'code' => 'VN', 'area_code' => 84
            ],
            'LA' => [
                'region' => 'Laos', 'name' => '老挝', 'code' => 'PH', 'area_code' => 856
            ],
            'KH' => [
                'region' => 'Cambodia', 'name' => '柬埔寨', 'code' => 'KH', 'area_code' => 855
            ],
            'MM' => [
                'region' => 'Myanmar', 'name' => '缅甸', 'code' => 'MM', 'area_code' => 95
            ],
            'TH' => [
                'region' => 'UThailand', 'name' => '泰国', 'code' => 'TH', 'area_code' => 66
            ],
            'MY' => [
                'region' => 'Malaysia', 'name' => '马来西亚', 'code' => 'MY', 'area_code' => 60
            ],
            'BN' => [
                'region' => 'Brunei', 'name' => '文莱', 'code' => 'BN', 'area_code' => 673
            ],
            'SG' => [
                'region' => 'Singapore', 'name' => '新加坡', 'code' => 'SG', 'area_code' => 65
            ],
            'ID' => [
                'region' => 'Indonesia', 'name' => '印度尼西亚', 'code' => 'ID', 'area_code' => 62
            ],
            'TL' => [
                'region' => 'East Timor', 'name' => '东帝汶', 'code' => 'TL', 'area_code' => 670
            ],
            'US' => [
                'region' => 'United States', 'name' => '美国', 'code' => 'US', 'area_code' => 1
            ]
        ];
        return $info[$code] ?: [];
    }

    /**
     * @param $area_code
     * @param $phone
     * @return string
     * 例如：17630301996 =》+8617630301996
     */
    public static function addCode($area_code, $phone): string
    {
        if (is_array($phone)) {
            return self::batchAddCode($area_code, $phone);
        }
        return self::ADD . $area_code . $phone;
    }

    /**
     * @param $area_code
     * @param $phones
     * @return string
     */
    public static function batchAddCode($area_code, $phones): string
    {
        $result = [];
        foreach ($phones as $phone) {
            $result[] = self::addCode($area_code, $phone);
        }
        return implode(',', $result);
    }


}